using System;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using EnvDTE80;

namespace TeamReview.Replay
{
	internal sealed class CodeElementFirstSnippetLink : CodeElementLink
	{
        public CodeElementFirstSnippetLink(EnvDTE80.DTE2 applicationObject, string workItemField, string displayField) : base(applicationObject, workItemField, displayField) 
        { }

		public override ReplayReceipt TryShowReplay(WorkItem workItem, DTE2 applicationObject)
		{
			ReplayReceipt receipt = base.TryShowReplay(workItem, applicationObject);
			if (!receipt.ItemWasFound)
				return receipt;

			receipt.ItemWasFound = false;
			string snippet = workItem.Fields[Constants.CODE_SNIPPET_FIELD].Value.ToString();
			FindCodeSnippet(receipt, snippet, String.Format("Review Item found by {0} name. Exact code found within the {0} body.", DisplayName));
			HighlightCodeSnippet(receipt);

			return receipt;
		}
	}
}
